package com.ww.core.widget.wheel;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.ww.core.R;
import com.ww.core.util.StringUtils;
import com.ww.core.widget.wheel.widget.MonthWheelAdapter;

/**
 * @since 
 * @version 2013-1-8
 * @author wwang
 */
public class WheelMonth {
	private View timePicker1;
	private MonthWheelAdapter wheelMain;
	private Button sure, cancel;

	private Context context;
	private TextView title;
	private Dialog dlg;

	public WheelMonth(Context context) {
		this.context = context;
	}

	/**
	 * 公共对话框.
	 * @param title 标题
	 * @param content 内容
	 * @param okClick 确定按钮点击事件.
	 * @return AlertDialog
	 */
	public void show(String date, OnClickListener click) {
		dlg = new Dialog(context, R.style.MyDialog);
		dlg.show();
		Window window = dlg.getWindow();
		window.setContentView(R.layout.core_wheel_2);
		timePicker1 = window.findViewById(R.id.timePicker1);
		title = (TextView) window.findViewById(R.id.title);
		wheelMain = new MonthWheelAdapter(timePicker1);
		wheelMain.initDateTimePicker(date);
		sure = (Button) window.findViewById(R.id.buttonsure);
		cancel = (Button) window.findViewById(R.id.buttoncancle);
		
		if (StringUtils.isNotEmpty(date)) {
			title.setText(date);
			title.setVisibility(View.VISIBLE);
		}

		sure.setOnClickListener(click);
		cancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				cancel();
			}
		});
	}
	
	

	public String getResult() {
		return wheelMain.getMonth();
	}

	public void cancel() {
		if (dlg != null) {
			dlg.cancel();
		}
	}

	
}